/* 
 * File:   Wind.cpp
 * Author: RedEyedKiller
 * 
 * Created on 2 Μάρτιος 2011, 5:25 πμ
 */

#include "Wind.h"
#include "../RandLib.h"
#include "../TimedUpdater.h"

namespace physicsSystem
{
namespace forces
{

Wind::Wind(float minIntensity, float maxIntesity, int minRad, int maxRad, int radStep/*=1*/)
{
    direction = true;
    this->minIntensity = minIntensity;
    this->maxIntesity = maxIntesity;
    this->maxRad = maxRad;
    this->minRad = minRad;
    this->radStep = radStep;
    angle = 90;
}

void Wind::Prepare(float seconds)
{
    CalculateForce();
}

void Wind::Affect(PhysicalObject* object)
{

}

void Wind::CalculateForce()
{
    float intensity = Math::Random(minIntensity, maxIntesity);
    static TimedUpdater tU;
    if (tU.Update(10))
        direction = Math::EventCheck(50);

    if (direction)
    {
        angle += radStep;
        if (angle > maxRad)
        {
            angle = maxRad;
        }
    }
    else
    {
        angle -= radStep;
        if (angle < minRad)
        {
            angle = minRad;
        }
    }

    force.Set(1, 0);
    force.RotateVector(angle);
    force *= intensity;
}

}
}
